import 'package:core_package/ui/widget/my_asset_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app_unionad/request/login_request.dart';
import 'package:flutter_app_unionad/ui/basice/base_navigation_widget.dart';
import 'package:core_package/core_package.dart';
import 'package:flutter_app_unionad/ui/basice/my_button.dart';
import 'package:flutter_app_unionad/ui/basice/select_title_and_detail_widget.dart';
import 'package:flutter_app_unionad/ui/basice/title_alert_widget.dart';
import 'package:flutter_app_unionad/ui/login/change_mobile_page.dart';
import 'package:flutter_app_unionad/ui/login/change_password_page.dart';
import 'package:flutter_app_unionad/view_model/page_manager_view_model.dart';

// ignore: must_be_immutable
class UserCenterItem10Page extends StatelessWidget {
  static const String routeName = "/userCenterItem10Page";

  @override
  Widget build(BuildContext context) {
    return BaseNavigationWidget(
      title: '安全中心',
      child: Column(
        children: [
          buildContentWidget(context),
          MySizeBox(height: 40),
          MyButton(
            title: "退出登录",
            onTap: () {
              ShowCenterAlertDialog.showAlert(context, height: 170.px, builder: (ctx) {
                return TitleAlertWidget(
                  title: "退出登录",
                  subTitle: "确定要退出登录吗?",
                  actions: ["点错了", "退出"],
                  actionsColors: [Colors.black12, MyColors.color_245_174_41],
                  actionsTitleColors: [Colors.white, Colors.white],
                  onTap: (index) {
                    if (index == 0) {
                      Navigator.pop(context, false);
                    } else {
                      Navigator.pop(context, true);
                    }
                  },
                );
              }).then(
                (value) async {
                  if (value != null && value) {
                    ///退出登录
                    await LoginRequest.saveJSPushRegister(registerID: '******');
                    Navigator.pop(context, "login");
                  }
                },
              );
            },
          ),
        ],
      ),
    );
  }

  Widget buildContentWidget(BuildContext context) {
    return Container(
      padding: EdgeInsets.only(left: 35.px, right: 30.px),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(5.px),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MySizeBox(height: 30),
          SelectTitleAndDetailWidget(
            title: "",
            detail: "修改电话",
            titleWidth: 0.px,
            icon: MyAssetImage(
              "icon_next",
              width: 5.px,
              height: 8.px,
            ),
            detailStyle: TextStyle(
              color: MyColors.formHex("#272727FF"),
              fontWeight: MyFontWeight.regular,
              fontSize: MyFont.font13,
            ),
            onTap: () {
              NavigatorUtil.push(context, ChangeMobilePage.routeName);
            },
          ),
          SelectTitleAndDetailWidget(
              title: "",
              detail: "修改密码",
              titleWidth: 0.px,
              icon: MyAssetImage(
                "icon_next",
                width: 5.px,
                height: 8.px,
              ),
              detailStyle: TextStyle(
                color: MyColors.formHex("#272727FF"),
                fontWeight: MyFontWeight.regular,
                fontSize: MyFont.font13,
              ),
              onTap: () {
                NavigatorUtil.push(context, ChangePasswordPage.routeName, arguments: true);
              }),
          MySizeBox(height: 30),
          SelectTitleAndDetailWidget(
              title: "",
              detail: "注销账号",
              titleWidth: 0.px,
              icon: MyAssetImage(
                "icon_next",
                width: 5.px,
                height: 8.px,
              ),
              detailStyle: TextStyle(
                color: MyColors.formHex("#272727FF"),
                fontWeight: MyFontWeight.regular,
                fontSize: MyFont.font13,
              ),
              onTap: () {
                ShowCenterAlertDialog.showAlert(context, height: 270.px, builder: (ctx) {
                  return TitleAlertWidget(
                    title: "注销账号",
                    subTitle: "1、该账号的全部个人资料和信息将无法找回\n2、确认注销后，7日内未登录即完成账号注销，如7日内登陆则自动解除注销",
                    actions: ["点错了", "确定注销"],
                    actionsColors: [Colors.black12, MyColors.color_245_174_41],
                    actionsTitleColors: [Colors.white, Colors.white],
                    onTap: (index) {
                      if (index == 0) {
                        Navigator.pop(context, false);
                      } else {
                        Navigator.pop(context, true);
                      }
                    },
                  );
                }).then(
                  (value) async {
                    if (value != null && value) {
                      ///退出登录
                      await LoginRequest.saveJSPushRegister(registerID: '******');
                      Navigator.pop(context, "login");
                    }
                  },
                );
              }),
          MySizeBox(height: 30),
        ],
      ),
    );
  }
}
